﻿using System;
using System.Web.Mvc;

namespace nsadv.Statistic.Web.RenderHelpers
{
	using ViewModels;

	public static class MenuItemRenderHelper
	{
		private static string MenuItemLinkStr(MenuItem item)
		{
			return String.Format("<a href=\"{0}\">{1}</a>", item.Url, item.Caption);
		}

		public static MvcHtmlString MenuItemLink(this HtmlHelper html, MenuItem item)
		{
			return MvcHtmlString.Create(MenuItemLinkStr(item));
		}

		public static MvcHtmlString Menu(this HtmlHelper html, Menu menu,
			string menuId = "menu",
			string menuClass = "menu",
			string activeItemClass = "active")
		{
			string str = "";
			foreach (var item in menu.Items)
				str = String.Format("{0}\n<li{2}>{1}</li>", str, MenuItemLinkStr(item), (item.Selected ? String.Format(" class=\"{0}\"", activeItemClass) : ""));
			str = string.Format("<ul id=\"{0}\" class=\"{1}\">\n{2}\n</ul>", menuId, menuClass, str);
			return MvcHtmlString.Create(str);
		}
	}
}